package com.example.hellospringboot.testWebMVC;

import com.example.hellospringboot.testWebMVC.ServletComment.MyFilter;
import com.example.hellospringboot.testWebMVC.ServletComment.MyListener;
import com.example.hellospringboot.testWebMVC.ServletComment.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import java.util.Arrays;

@Configuration
public class ServletConfig {
    @Bean
//    servlet组件的注册
    public ServletRegistrationBean getServlet(MyServlet myServlet){
        ServletRegistrationBean<MyServlet> myServletServletRegistrationBean
                =new ServletRegistrationBean<>(myServlet,"/myServlet");
        return myServletServletRegistrationBean;
    }
    @Bean
//    filter组件的注册
    public FilterRegistrationBean getFilter(MyFilter myFilter){
        FilterRegistrationBean<Filter> filterFilterRegistrationBean=new FilterRegistrationBean<>(myFilter);
        filterFilterRegistrationBean.setUrlPatterns(Arrays.asList("/toLoginPage"));
        return filterFilterRegistrationBean;
    }
//    @Bean
////    listener组件的注册
//    public ServletListenerRegistrationBean getListener(MyListener myListener){
//        ServletListenerRegistrationBean<MyListener> myListenerServletListenerRegistrationBean=new ServletListenerRegistrationBean<>(myListener);
//    return myListenerServletListenerRegistrationBean;
//
//    }
}
